﻿using System;
using System.Collections.Generic;
using System.Text;

namespace HZ.Common
{
    /// <summary>
    /// 加密接口，使用新的加密方法，实现该接口即可。
    /// </summary>
    public interface IEncrypt
    {
        string EncryptString(string price, params string[] pwd);
        string DecryptString(string price, params string[] pwd);
        bool SetKey { get; }
        byte[] Key { set; }
        byte[] IV { set; }
    }


    /// <summary>
    /// 加密类工厂
    /// </summary>
    public sealed class EncryptFactory
    {
        /// <summary>
        /// 创建加密接口
        /// </summary>
        /// <param name="classname">加密类类名</param>
        /// <param name="_namespace">加密类的命名空间</param>
        /// <returns>加密接口</returns>
        public static IEncrypt CreateEncrypt()
        {
            string enclass = System.Configuration.ConfigurationManager.AppSettings["EncryptClass"];
            if (string.IsNullOrEmpty(enclass))
            {
                throw new Exception("配置文件AppSettings EncryptClass 不存在，请设置加密类配置文件。");
            }
            int lastpoint = enclass.LastIndexOf(".");
            string _namespace = enclass.Substring(0, lastpoint);
            return (IEncrypt)System.Reflection.Assembly.Load(_namespace).CreateInstance(enclass);
        }
    }
}